import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [

  {
    path: '/',
    redirect: '/ligon'
  },
  {
    // 登录界面
    path: '/content',
    name: '/content',
    component: () => import('../view/content')
  },
  {
    path: '/ligon',
    name: '/ligon',
    component: () => import('../view/ligon')
  }, {
    path: '/menu',
    name: '/menu',
    component: () => import('../view/menu')
  },
   

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 定义路由导航前置守卫
router.beforeEach((to, from, next) => {
  // NProgress.start()
  // next()
  let newname = localStorage.getItem("用户名")
  let newmima = localStorage.getItem('密码')
  if (to.path == '/content') {
      if (newname && newmima) {
          next({ name: 'ligon' })
      } else {
          next()
      }
  } else {
      if (newname && newmima) {
          // console.log(to);
          next()
      } else {
          next({ name: 'content' })
      }
  }
})
// 定义路由导航后置守卫
// router.afterEach((to, from) => {
  // NProgress.done()
// })
export default router

